var house_detail = new Vue({
    el: "#house_detail",
    data:{
        houseUrl:"api/sys/house/houseDetail?id=",
        questionUrl:"api/sys/question/random",
        menuUrl: "api/sys/index/menuCol",
        menuData:{},
        houseDetail:{},
        questions:{},
        id:""
    },
    mounted:function () {
        this.setPageType();//获取当前链接类型
        this.getInfoContent();
    },
    updated: function () {//数据加载完触 发
        //加载完图片，开始处理轮播
        this.swiperStart();
        menu_hover();
        // 修改富文本中图片，做响应式处理
        $(".itemDescription img").addClass("img-responsive");
    },
    methods: {
        setPageType:function(){
            this.id = this.getQueryString('id');
        },
        getQueryString:function (name) {//获取链接 参数
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        },
        getInfoContent:function () {
            this.$http.get(baseUrl + this.houseUrl + this.id).then(//房源详情
                function (res) {
                    this.houseDetail = res.data.data;
                    this.houseDetail.pics = this.houseDetail.pics.split('|');
                    $("title").html(this.houseDetail.tkdTitle);
                    $("meta[name='keywords']").attr("content",this.houseDetail.tkdKeywords);
                    $("meta[name='description']").attr("content",this.houseDetail.tkdDesc);
                }
            ).catch(function (response) {
                console.log(response)
            })
            this.$http.get(baseUrl + this.questionUrl).then(//随机2个问题
                function (res) {
                    this.questions = res.data.data;
                }
            ).catch(function (response) {
                console.log(response)
            })

            this.$http.get(baseUrl + this.menuUrl).then(
                function (res) {
                    this.menuData = res.data.data;
                }
            ).catch(function (response) {
                console.log(response)
            })
        },
        swiperStart: function () {//轮播图片处理
            //点击切换轮播
            var listImg = $('.carouselMessage').find('li');
            listImg.click(function () {
                for (var i = 0; i < listImg.length; i++) {
                    $('.carouselMessage').carousel($(this).index());
                }
            });
            //轮播图启动
            var mySwiper = new Swiper('.swiper-container', {
                loop: true,
                autoplay: true,
                pagination: {
                    el: '.swiper-pagination',
                    clickable: true
                },
            });
        }
    },
    filters: {
        formatDate: function (val) {
            var value = new Date(val);
            var year = value.getFullYear();
            var month = padDate(value.getMonth() + 1);
            /*var day = house_detail.padDate(value.getDate());
            var hour = house_detail.padDate(value.getHours());
            var minutes = house_detail.padDate(value.getMinutes());
            var seconds = house_detail.padDate(value.getSeconds());*/
            return year + '年' + month + '月';
        },
        cutOut:function (val) {
            return val.substring(0,160);
        },
        formatNullStr:function (val) {
            if(!val){
                return "-"
            }
            return val;
        }
    }
})